
<?php
require_once 'PIView.php';
	class ResidentManager{
	
		public function validate($snum,$fnme,$lnme,$mnme,$bday,$gendr,$cstatus,$lschool,$lschtype,$religion,$class,$stfap,$schol,$stipe,$cp,$email,$hobbies,$honors,$talents,$ailments,$meds,$addres,$fdnme,$fjob,$faddress,$fincome,$flife,$femployer,$fcp,$mdnme,$mjob,$maddress,$mincome,$mlife,$memployer,$mcp,$regn,$stats,$numbro,$numsis,$order,$gnme,$gadd,$gnum,$course,$college){
		
				if(is_numeric($snum)&&is_numeric($stipe)&&is_numeric($cp)&&($fname!=""||$fname!=null)&&($lname!=""||$lname!=null)&&($bday!=""||$bday!=null)
				&&($gendr!=""||$gendr!=null)&&($cstatus!=""||$cstatus!=null)&&($lschool!=""||$lschool!=null)&&($lschtype!=""||$lschtype!=null)&&($religion!=""||$religion!=null)
				&&($class!=""||$class!=null)&&($stfap!=""||$stfap!=null)&&($cp!=""||$cp!=null)&&($email!=""||$email!=null)&&($gname!=""||$gname!=null)&&($gadd!=""||$gadd!=null)&&($course!=""||$course!=null)&&is_numeric($gnum)){
						return true;
					}else{
						return false;
				}
		}
		

		
		
		public function insertResident($snum,$fnme,$lnme,$mnme,$bday,$gendr,$cstatus,$lschool,$lschtype,$religion,$class,$stfap,$schol,$stipe,$cp,$email,$hobbies,$honors,$talents,$ailments,$meds,$addres,$fdnme,$fjob,$faddress,$fincome,$flife,$femployer,$fcp,$mdnme,$mjob,$maddress,$mincome,$mlife,$memployer,$mcp,$regn,$stats,$numbro,$numsis,$order,$gnme,$gadd,$gnum,$course, $college){
				
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err[] = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$stid = oci_parse($conn,"insert into student(studentno,namefirst,namelast,namemiddle,birthdate,gender,civilstatus,lastschool,lastschooltype,religion,classification,stfapbracket,scholarships,allowance,cellno,email,hobbies,honors,talents,ailments,medications,homeaddress,course,college) values(:studentno,:namefirst,:namelast,:namemiddle,:birthdate,:gender,:civilstatus,:lastschool,:lastschooltype,:religion,:classification,:stfapbracket,:scholarships,:allowance,:cellno,:email,:hobbies,:honors,:talents,:ailments,:medications,:homeaddress,:course,:college)");
				oci_bind_by_name($stid, ":studentno", $snum);
				oci_bind_by_name($stid, ":namefirst", $fnme);
				oci_bind_by_name($stid, ":namelast", $lnme);
				oci_bind_by_name($stid, ":namemiddle", $mnme);
				oci_bind_by_name($stid, ":birthdate", $bday);
				oci_bind_by_name($stid, ":gender", $gendr);
				oci_bind_by_name($stid, ":civilstatus", $cstatus);
				oci_bind_by_name($stid, ":lastschool", $lschool);
				oci_bind_by_name($stid, ":lastschooltype", $lschtype);
				oci_bind_by_name($stid, ":religion", $religion);
				oci_bind_by_name($stid, ":classification", $class);
				oci_bind_by_name($stid, ":stfapbracket", $stfap);
				oci_bind_by_name($stid, ":scholarships", $schol);
				oci_bind_by_name($stid, ":allowance", $stipe);
				oci_bind_by_name($stid, ":cellno", $cp);
				oci_bind_by_name($stid, ":email", $email);
				oci_bind_by_name($stid, ":hobbies", $hobbies);
				oci_bind_by_name($stid, ":honors", $honors);
				oci_bind_by_name($stid, ":talents", $talents);
				oci_bind_by_name($stid, ":ailments", $ailments);
				oci_bind_by_name($stid, ":medications", $meds);
				oci_bind_by_name($stid, ":homeaddress", $addres);
				oci_bind_by_name($stid, ":course", $course);
				oci_bind_by_name($stid, ":college", $college);

				$exec1 = oci_execute($stid);

				$stid2 = oci_parse($conn,"insert into parents(studentno,fathername,fjob,foffice,fincome,flife,femployer,ftelnum,mothername,mjob,moffice,mincome,mlife,memployer,mtelnum) values(:studentno,:fathername,:fjob,:foffice,:fincome,:flife,:femployer,:ftelnum,:mothername,:mjob,:moffice,:mincome,:mlife,:memployer,:mtelnum)");
				oci_bind_by_name($stid2, ":studentno", $snum);
				
				oci_bind_by_name($stid2, ":fathername", $fdnme);
				oci_bind_by_name($stid2, ":fjob", $fjob);
				oci_bind_by_name($stid2, ":foffice", $faddress);
				oci_bind_by_name($stid2, ":fincome", $fincome);
				oci_bind_by_name($stid2, ":flife", $flife);
				oci_bind_by_name($stid2, ":femployer", $femployer);
				oci_bind_by_name($stid2, ":ftelnum", $fcp);
				
				oci_bind_by_name($stid2, ":mothername", $mdnme);
				oci_bind_by_name($stid2, ":mjob", $mjob);
				oci_bind_by_name($stid2, ":moffice", $maddress);
				oci_bind_by_name($stid2, ":mincome", $mincome);
				oci_bind_by_name($stid2, ":mlife", $mlife);
				oci_bind_by_name($stid2, ":memployer", $memployer);
				oci_bind_by_name($stid2, ":mtelnum", $mcp);


				$exec2 = oci_execute($stid2);

				$stid3 = oci_parse($conn,"insert into family(studentno,region,parentmarriagestatus,numbrothers,numsisters,orderbirth) values(:studentno,:region,:parentmarriagestatus,:numbrothers,:numsisters,:orderbirth)");
				oci_bind_by_name($stid3, ":studentno", $snum);
				
				oci_bind_by_name($stid3, ":region", $regn);
				oci_bind_by_name($stid3, ":parentmarriagestatus", $stats);
				oci_bind_by_name($stid3, ":numbrothers", $numbro);
				oci_bind_by_name($stid3, ":numsisters", $numsis);
				oci_bind_by_name($stid3, ":orderbirth", $order);

				$exec3 = oci_execute($stid3);

				$stid4 = oci_parse($conn,"insert into guardian(studentno,name,address,telno) values(:studentno,:name,:address,:telno)");
				oci_bind_by_name($stid4, ":studentno", $snum);
				
				oci_bind_by_name($stid4, ":name", $gnme);
				oci_bind_by_name($stid4, ":address", $gadd);
				oci_bind_by_name($stid4, ":telno", $gnum);


				$exec4 = oci_execute($stid4);
				
				if(($exec1==true)&&($exec2==true)&&($exec3==true)&&($exec4==true)){
					return 1;
				}
				
				oci_commit($conn);
				//oci_free_statement($stid);
				oci_close($conn);
	
			}	
		
		}		
		
	}//class
	

	
	
?>
